import 'package:flutter/material.dart';
import 'package:flutter_massage/common_lib/index.dart';
import 'package:flutter_massage/pages/message/index.dart';
import 'package:flutter_massage/pages/message/message_logic.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class MessagePage extends StatefulWidget {
  const MessagePage({super.key});

  @override
  State<MessagePage> createState() => _MessagePageState();
}

class _MessagePageState extends State<MessagePage> with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    super.build(context);
    return const _MessageView();
  }

  @override
  bool get wantKeepAlive => true;
}

class _MessageView extends GetView<MessageLogic> {
  const _MessageView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BaseScaffold(
      titleStr: '消息',
      hideBackBtn: true,
      child: GetBuilder<MessageLogic>(
        init: MessageLogic(),
        assignId: true,
        builder: (logic) {
          if (logic.list.isEmpty) return const Center(child: Text('暂无消息'));
          // return ListView.separated(
          //   itemCount: logic.list.length + 1,
          //   itemBuilder: (BuildContext context, int index) {
          //     if (index == 0) return const MessageListSystemItem();
          //     return MessageListItem(logic.list[index - 1]);
          //   },
          //   separatorBuilder: (BuildContext context, int index) => CommonDivider(marginLeft: 12.w, marginRight: 12.w),
          // );
          return ListView.separated(
            itemCount: logic.list.length,
            itemBuilder: (BuildContext context, int index) {
              return MessageListItem(logic.list[index]);
            },
            separatorBuilder: (BuildContext context, int index) => CommonDivider(marginLeft: 12.w, marginRight: 12.w),
          );
        },
      ),
    );
  }
}
